package com.xxk.rocket.star.core.context;

import com.alibaba.rocketmq.client.producer.MQProducer;
import com.xxk.rocket.star.core.dto.ProducerMethodsDTO;
import com.xxk.rocket.star.core.exception.StargateException;
import org.apache.commons.beanutils.BeanUtils;

public class ProducerContext extends StargateContext {

  protected MQProducer mqProducer;

  @Override
  public ProducerContext clone() {
    ProducerContext producerContext = new ProducerContext();
    try {
      for (Class aClass : data.keySet()) {
        Object o = data.get(aClass);
        producerContext.data.put(aClass, BeanUtils.cloneBean(o));
      }
    } catch (Exception e) {
      throw new StargateException("copy ConsumeContext error:", e);
    }
    return producerContext;
  }

  @Override
  public boolean isValid() {
    ProducerMethodsDTO producerMethodsDTO = (ProducerMethodsDTO) data
            .get(ProducerMethodsDTO.class);
    return producerMethodsDTO.isValid();
  }

  public MQProducer getMqProducer() {
    return mqProducer;
  }

  public void setMqProducer(MQProducer mqProducer) {
    this.mqProducer = mqProducer;
  }

}
